package cn.dgut.jy.soro.service.impl;

import cn.dgut.jy.soro.entity.Product;
import cn.dgut.jy.soro.repository.ProductRepository;
import cn.dgut.jy.soro.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
    private ProductRepository productRepository;

    @Autowired
    public ProductServiceImpl(ProductRepository productRepository) {
        this.productRepository = productRepository;
    }

    @Override
    public Boolean add(String name, Float price, String details) {
        Product product = new Product();
        product.setName(name);
        product.setPrice(price);
        product.setDetails(details);
        if (productRepository.findByName(name) != null) {
            return false;
        }
        productRepository.save(product);
        return true;
    }
}
